package cn.itcast.bos.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.CourierRepository;
import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.service.CourierService;
@Service("courierService")
@Transactional
public class CourierServiceImpl implements CourierService {
	
	@Autowired
	private CourierRepository courierRepository;

	@Override
	public void save(Courier courier) {
		courierRepository.save(courier);
	
	}

	//courier分页查询
	@Override
	public Page<Courier> findAll(Pageable pageable) {
		return courierRepository.findAll(pageable);
	}

	@Override
	public Page<Courier> findPageQueryCourierByCondition(Specification<Courier> specification, Pageable pageable) {
		return courierRepository.findAll(specification, pageable);
	}

	//作废快递员信息
	@Override
	public void delete(String[] courierArr) {
		if(courierArr != null){
			for (String id : courierArr) {
				courierRepository.updateDelTag(Integer.parseInt(id));
			}
		}
		
	}

	//恢复作废快递员信息
	@Override
	public void restore(String[] courierArr) {
		if(courierArr != null){
			for (String id : courierArr) {
				courierRepository.restore(Integer.parseInt(id));
			}
		}
	}

	//定区关联有效快递员
	@Override
	public List<Courier> findnoassociation() {
		List<Courier> list = courierRepository.findAllCouriers();
		return list;
	}

	
	@Override
	public List<Courier> findAssociationCourier(String fixedAreaId) {
		return courierRepository.findAssociationCourier(fixedAreaId);
	}

	
	
}
